import java.util.PriorityQueue;
import java.util.Stack;
import java.util.TreeMap;

/**
 * @author VernHe
 * @date 2021年06月10日 13:17
 */
public class MinStack {
    public static void main(String[] args) {
        /**
         * ["push","push","push","top","pop","getMin","pop","getMin","pop","push","top","getMin","push","top","getMin","pop","getMin"]
         */
        MinStack minStack = new MinStack();
        minStack.push(2147483646);
        minStack.push(2147483646);
        minStack.push(2147483647);
        minStack.top();
        minStack.pop();
        minStack.getMin();
        minStack.pop();
        minStack.getMin();
        minStack.pop();
        minStack.push(2147483647);
        minStack.top();
        minStack.getMin();
        minStack.push(-2147483648);
        minStack.top();
        minStack.getMin();
        minStack.pop();
        minStack.getMin();

    }
    Stack<Integer> stack;
    PriorityQueue<Integer> priorityQueue;
    /** initialize your data structure here. */
    public MinStack() {
        stack = new Stack();
        priorityQueue = new PriorityQueue<>();
    }

    public void push(int val) {
        stack.push(val);
        priorityQueue.add(val);
        System.out.println("插入元素后队头：" + priorityQueue.peek());
    }

    public void pop() {
        Integer pop = stack.pop();
        System.out.println("弹出栈顶元素：" + pop);
        System.out.println("当前栈顶元素: " + (stack.size() == 0 ? "无" :stack.peek()));
        priorityQueue.remove(pop);
        System.out.println("弹出元素后队头: " + priorityQueue.peek());
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return priorityQueue.peek();
    }

    private void showStack() {

    }

}

/**
 * [2147483647,2147483646,2147483646,2147483647,2147483647,-2147483648,-2147483648,2147483647]
 */